package com.lingshi.shopping_manager_api.security;

import cn.dev33.satoken.stp.StpUtil;
import com.lingshi.common.exception.BusException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;

import static com.lingshi.common.enums.BusCodeEnum.NOT_LOGIN_ERROR;

public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断是否登录
        if(!StpUtil.isLogin()){
            BusException.busException(NOT_LOGIN_ERROR);
        }
        return true;//放行
    }

}
